<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Log;
use Org\Util\Page;
 

class RequirementsController extends BaseController {

//需求记录列表
    public function Purchasing(){
        /* $lie = M('procreq');
     	$sql = $lie->order("demand_time desc,actual_date desc")->select(); 
        $this->assign("sql",$sql);
        $this->display(); */
		
		
		$m=M("procreq");
		$keywords=I("param.keywords");
		$start_time=I("param.start_time");
		$end_time=I("param.end_time");
		$wheres=array();
		if(I("param.listrows"))
		{
			$where['listrows']=I("param.listrows");

		}
		if($keywords)
		{
			$wheres['goods_englishname|actual_goods_sn']=array('like',"%".trim($keywords)."%");
		}
		if($start_time)
		{
			$wheres['procreq_time']=array('egt',$start_time);
		}
		if($end_time)
		{
			$wheres['procreq_time']=array('elt',$end_time);
		}
		if($start_time && $end_time)
		{
			$wheres['procreq_time']=array(array('egt',$start_time),array('elt',$end_time),"and");
		}
		$where['where']=$wheres;
		$where['order']="demand_time desc,warning_stock_quantity desc";
		$results = $this->_getListsViewSpecial($m, $where);
		
		$this->assign("sql",$results['lists']);
		$this->assign("show",$results['page_html']);
		$this->display();
    }

public function add(){
        $email_id = I('procreq_id');

        $email_id = intval($email_id);
       // $email_id = empty($email_id)?$0:$email_id;
        if($email_id>0)
          $rel = M('procreq')->where('procreq_id='.$email_id)->find();

         $this->assign('procreq',$rel);
         $this->display();
          }
public function edit(){
     $data = $_POST;
     $data['adminuser'] = UID;
    $data["add_time"] = date("Y-m-d H:i:s");
  if (empty($_POST["email_id"])||$_POST["email_id"] == 0) {
      unset ( $data ["email_id"] );
      $result = M ( "procreq" )->add ( $data );
    } else {
      $data ["email_id"] = $data ["email_id"]; 
      $result = M ( "procreq" )->save ( $data );
    }

    if($result){
      $this->success ( "操作成功!");
    }else{
    $this->error ( "操作失败!");
    }
}




/* //添加方法
        public function add(){
            if(!empty($_POST)){
            	$data['goods_englishname'] = $_POST['goods_englishname'];
            	$data['warning_stock_quantity'] = $_POST['warning_stock_quantity'];
            	$data['actual_stock_quantity'] = $_POST['actual_stock_quantity'];
            	$data['demand_time'] = $_POST['demand_time']; 
            	$data['sactive'] = $_POST['sactive']; 
            	$data['procreq_time'] = date("Y-m-d H:i:s");
                    $res = M('procreq');
                    if(($data['goods_englishname']!="") &&($data['warning_stock_quantity']!="")&&($data['actual_stock_quantity']!="")&&($data['demand_time']!="")&&($data['sactive']!="")&&($data['procreq_time'] !="")){
                    	$resData = $res->add($data);
                          if($resData){
                              $this->success("添加成功");
                          }else{
                            $this->error("添加失败");
                          }
                    }else{
                       $this->error("数据不完整");
                    }
                       
            }else{
               $this->display();
            }

        }
      //  编辑
        public function edit(){
         
              if(!empty($_GET['procreq_id'])){ 

                 $res = M("procreq");
                  if(!empty($_POST)){
                      $data['goods_englishname'] = I("post.goods_englishname");
                      $data['warning_stock_quantity'] = I("post.warning_stock_quantity");
                      $data['actual_stock_quantity'] = I("post.actual_stock_quantity");
                      $data['demand_time'] = I("post.demand_time"); 
                      $data['sactive'] = I("post.sactive");
                      $data['procreq_time'] = date("Y-m-d H:i:s");
                      
                      $boolData =$res->where("procreq_id={$_REQUEST['procreq_id']}")->save($data);
                     
                          if($boolData){
                              $this->success("修改成功");
                          }else{
                              $this->error("修改失败");
                          }
                  }else{
                      $id = I("get.procreq_id");
                      $arrData = $res->where('procreq_id='.$id)->select();
                      $this->assign("arrData",$arrData);
                      $this->display();
                  }
              }else{
                  $this->error("没有数据");
              }
        }*/

		//删除
		public function det(){
		        $id = I("get.procreq_id");
		          
		        $shanchu = M("procreq");
		        $bool = $shanchu->delete($id);
		          
		        if($bool){
		          $this->success("删除成功");
		        }else{
		          $this->error("没有数据删除失败");
		        }
		}






}



?>